package com.yc.cloud.portal.controller;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.portal.request.ARControlParam;
import com.yc.cloud.portal.request.AROCRParam;
import com.yc.cloud.portal.request.ARRTCCallbackParam;
import com.yc.cloud.portal.service.ARService;
import com.yc.cloud.portal.vo.OCRResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/ar")
@Api(tags = "AR模块")
@Slf4j
public class ARController {

    private final ARService arService;

    public ARController(ARService arService) {
        this.arService = arService;
    }

    @PostMapping("/rtccallback")
    @ApiOperation(value = "RTC回调接口", notes = "RTC回调接口")
    public ResponseResult<Boolean> rtcCallBack(@RequestBody @Validated ARRTCCallbackParam param) {
        log.info("RTC回调接口, param={}", param);
        val result = arService.rtcCallBack(param);
        return result ? ResponseResult.success(true) : ResponseResult.failed("RTC回调失败");
    }

    @PostMapping("/control")
    @ApiOperation(value = "控制AR设备接口", notes = "包含多种事件,如拍照、录像、显示图片、获取GPS等操作")
    public ResponseResult<Boolean> controlARDevice(@RequestBody @Validated ARControlParam param) {
        log.info("控制AR设备接口, param={}", param);
        val result = arService.controlARDevice(param);
        return result ? ResponseResult.success(true) : ResponseResult.failed("控制AR设备失败");
    }

    @PostMapping("/ocr")
    @ApiOperation(value = "OCR识别", notes = "提取图片中的文字信息")
    public ResponseResult<OCRResultVo> ocr(@RequestPart MultipartFile file, @Validated AROCRParam param) {
        log.info("OCR识别接口");
        val result = arService.ocr(param, file);
        return ResponseResult.success(result);
    }
}
